<template>
  <div class="address">
    <van-nav-bar title="收货地址" left-arrow @click-left="onClickLeft" />
    <div class="content">
      <img src="../../assets/lsc/address.jpg" alt="" />
      <p>您还没有地址信息</p>
    </div>
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认地址"
      @add="onAdd"
      @edit="onEdit"
    />
  </div>
</template>

<script>
// import Vue from "vue";
// import { Cell, CellGroup } from "vant";
import { Toast } from "vant";
// Vue.use(Cell);
// Vue.use(CellGroup);
import axios from "axios";

export default {
  created() {
    axios({
      url: "apf/addr/selectAddrByUserId/2",
    }).then((res) => {
      console.log(res.data.data);
      res.data.data.forEach((item) => {
        this.list.push({
          id: item.id,
          name: item.userName,
          tel: item.tel,
          address: item.detailAddr + item.houseNumber,
          isDefault:
            item.defaultAddr == 1
              ? (this.isDefault = true)
              : (this.isDefault = false),
        });
      });
    });
  },
  methods: {
    onClickLeft() {
      this.$router.push("/profile");
    },
    relieve() {},
    onAdd() {
      Toast("新增地址");
      this.$router.push("/add");
    },
    onEdit(item) {
      console.log("item", item);

      this.$router.push({
        path: "/amend",
        query: { id: item.id },
      });
    },
  },

  data() {
    return {
      chosenAddressId: "1",
      list: [],
    };
  },
};
</script>

<style scoped>
.address {
  width: 100%;
  min-height: 6.4rem;
  background-color: #efeff4;
}
/deep/.van-nav-bar {
  background-color: #f5f5f5;
}
/deep/.van-nav-bar .van-icon {
  color: gray;
}

.van-button--round {
  background-color: #6d87c4;
  border: none;
}
/deep/.van-address-item .van-radio__icon--checked .van-icon {
  background-color: #6d87c4;
  border: #6d87c4;
}
.van-tag--danger {
  background-color: #6d87c4;
}
.content {
  margin-top: 0.7rem;
  text-align: center;
  display: none;
}
.van-address-item {
  /* display: none; */
}
.content img {
  width: 1rem;
}
.content p {
  margin-top: 0.12rem;
  font-size: 0.14rem;
  color: #ccc;
}
.van-address-list__bottom {
  background-color: #f5f5f5;
  border: none;
}
</style>
